Skip to content

Conversation

@rodrigogiraoserrao
Copy link
Contributor

This will close #2457.

I've added a docstring but I haven't added documentation elsewhere. Should I?

@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review May 9, 2023 14:01
}
"""

auto_focus: str | None = "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this an instance var, which should be the default unless there is good rationale for it being a classvar.

Copy link
Contributor Author

@rodrigogiraoserrao rodrigogiraoserrao May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because it's a pain to set it as an instance attribute-only for people creating their own screens:

class FormScreen(Screen):
    auto_focus = "Input"

    ...

vs

class FormScreen(Screen):
    def __init__(
        self,
        name: str | None = None,
        id: str | None = None,
        classes: str | None = None,
    ) -> None:
        self.auto_focus = "Input"
        super().__init__(name=name, id=id, classes=classes)

    ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want it to be a classvar, suggest we make it a constant, i.e. AUTO_FOCUS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classvar it is.

Copy link
Member

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually rather surprised this didn't break any unit tests.

@rodrigogiraoserrao rodrigogiraoserrao merged commit 83618db into main May 15, 2023
@rodrigogiraoserrao rodrigogiraoserrao deleted the auto-focus branch May 15, 2023 10:04
davep added a commit to davep/textual that referenced this pull request Jun 1, 2023
See Textualize#2718. The problem is that the work done on Textualize#2527 and related PRs has
changed the starting position of focus, which means that any code example
that has key presses in them that start out by tabbing to a control will be
off by one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to auto focus the first thing on a screen.

3 participants